//
//  ShmIdentificationModel.swift
//  ParsingCC
//
//  Created by ins-yangming on 2023/1/6.
//

import UIKit

class ShmIdentificationModel: NSObject {
    var rights = "数淼音乐";
    var encoding : [String : Any] = ["encoding-date" : "2023-01-06" , "encoder" : "Administrator", "software<|||>1" : "Sibelius 8.2.0", "software<|||>2" : "Direct export, not from Dolet", "encoding-description" : "Sibelius / MusicXML 3.0", "supports<|||>1" : ["element":"print","type":"yes", "value" : "yes", "attribute" : "new-system"], "supports<|||>2" : ["element":"print","type":"yes", "value" : "yes", "attribute" : "new-page"], "supports<|||>3" : ["element":"accidental","type":"yes"], "supports<|||>4" : ["element":"beam","type":"yes"], "supports<|||>5" : ["element":"stem","type":"yes"]];
    
    func getXmlElement() -> GDataXMLElement{
        let identificationElement = GDataXMLNode.element(withName: "identification");
        let rightsElement = GDataXMLNode.element(withName: "rights", stringValue: self.rights);
        identificationElement?.addChild(rightsElement!);
        
        let encodingElement = GDataXMLNode.element(withName: "encoding");
    
        
        for (key , value) in self.encoding {
            if let stringValue = value as? String {
                let name = key.components(separatedBy: "<|||>").first ?? ""
                let element = GDataXMLNode.element(withName: name, stringValue: stringValue);
                encodingElement?.addChild(element);
            }
            if let dic = value as? [String : String] {
                let name = key.components(separatedBy: "<|||>").first ?? ""
                let element = GDataXMLNode.element(withName: name);
                for (key2 , value2) in dic {
                    if let attribute = GDataXMLNode.attribute(withName: key2, stringValue: value2) as? GDataXMLNode {
                        element?.addAttribute(attribute);
                    }
                }
                encodingElement?.addChild(element);
            }
            
        }
        identificationElement?.addChild(encodingElement!);
        return identificationElement!;
    }
}
